#!/usr/bin/env python3
# coding: utf-8

#!/usr/bin/env python3
#codings: utf-8

import numpy as np
import cv2 as cv
KEY_ESC = 27

def show_color(x):
    print("color",x)

img = np.zeros((500,500,3),np.uint8)
window_name='image'
cv.namedWindow(window_name)
cv.createTrackbar('R',window_name,0,255,show_color)
cv.createTrackbar('G',window_name,0,255,show_color)
cv.createTrackbar('B',window_name,0,255,show_color)


def show_status(x):
    print("on,off status:",x)

switch_window="0:off 1:on"
cv.createTrackbar(switch_window,window_name,0,1,show_status)
while True:
    cv.imshow(window_name,img)
    r = cv.getTrackbarPos('R',window_name)
    g = cv.getTrackbarPos('G',window_name)
    b = cv.getTrackbarPos('B',window_name)
    status = cv.getTrackbarPos(switch_window,window_name)
    if status == 0:
        img[:] = [0,0,0]
    else:
        img[:]=[b,g,r]
    print("R:%u G:%u B:%u"%(r,g,b))
    key = cv.waitKey(100) & 0xff
    if key == KEY_ESC:
        break

cv.destroyAllWindows()
